package cn.iocoder.devlop.module.annual.report.common.service;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.iocoder.devlop.module.annual.report.common.dal.EnttypeAntypeMapper;
import cn.iocoder.devlop.module.annual.report.common.dal.dataobject.EnttypeAntypeDO;
import cn.iocoder.devlop.module.infra.util.ConfigUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class EnttypeAntypeService {

    @Resource
    private EnttypeAntypeMapper enttypeAntypeMapper;


    public String getAntype(String enttype) {
        EnttypeAntypeDO  enttypeAntypeDO = enttypeAntypeMapper.selectByEnttype(enttype);
        if (ObjectUtil.isNull(enttypeAntypeDO)){
            return null;
        }
        return enttypeAntypeDO.getAntype();
    }

    public JSONObject getJson(String enttype) {
        String antype = getAntype(enttype);
        String key = "";
        if (StrUtil.isNotBlank(antype)){
            switch (antype) {
                case "10":
                case "20":
                    key = "standard.publicMain";
                    break;
                case "11":
                case "21":
                    key = "standard.privateMain";
                    break;
                case "30":
                    key = "standard.publicBranch";
                    break;
                case "31":
                    key = "standard.privateBranch";
                    break;
            }
        }
        if (StrUtil.equals(enttype,"9600")){
            key = "standard.individual";
        } else if (StrUtil.equals(enttype,"9100")){
            key = "standard.farmer";
        }
        return JSONUtil.parseObj(ConfigUtils.getConfigByKey(key));
    }
}
